﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PMSSys
{
    public partial class PaymentView : Form
    {
        public PaymentView(string payment_id, paymentController payController)
        {
            InitializeComponent();
            payObject = new Payment(); 
            this.payController = payController;
            if (addMode = String.IsNullOrEmpty(payment_id))
            {
            }
            else
            {
                payObject.PaymentID = int.Parse(payment_id);
                payController.objectFiller(payObject);
                dateTimePicker1.Value = payObject.PayDate;
                textBox1.Text = payObject.Services.ToString();
                textBox2.Text = payObject.Amount.ToString();
                isModified = false;
            }
        }
        private Payment payObject;
        private paymentController payController;
        private bool isModified = false;
        private bool addMode = false;
        private void closeLogic(object sender, EventArgs e)
        {
            this.Close();
        }

        private void modifiedCheck(object sender, EventArgs e)
        {
            isModified = true;
        }

        private void PaymentView_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (isModified)
            {
                DialogResult res = uiUtility.confirmSaveDialog();
                if (res != DialogResult.Cancel)
                {
                    if (res == DialogResult.Yes)
                    {
                        Double result;
                        if (Double.TryParse(textBox2.Text, out result) || textBox1.Text != String.Empty)
                        {
                            if (addMode)
                            {
                            }
                            else
                            {
                            }
                        }
                        else
                        {
                            MessageBox.Show("Invalid character in Payment field detected", "Invalid Payment", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            e.Cancel = true;
                        }

                    }

                }
                else
                    e.Cancel = true;
            }
        }

        private void PaymentView_Load(object sender, EventArgs e)
        {
            ToolTip t1 = uiUtility.tooltips();
            t1.SetToolTip(this.button6, "Back");
        }
    }
}
